from flask import Flask,render_template
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import func,or_
from setting import config
db:SQLAlchemy = SQLAlchemy()
from job.models import Job
def create_app(config=config):

    
    app = Flask(__name__)
    app.config.from_object(config)
    if app.config['ENV']=='production':
        print("部署用的模式...")
    elif app.config['ENV']=='development':
        print("开发用的模式...")
    @app.route("/")
    def index():

        return render_template("ind2.html")

    # @app.route("/ind")
    # def ind():
    #     num = db.session.execute("select province,sum(num) from job  group by province").fetchall()#省份招聘数量
    #     shuliang = db.session.execute("select count(*) from job").fetchall() #总招聘数量
    #     cate2 = db.session.execute("select * from(select cate2,count(*) as num from job group by cate2) job order by num DESC limit 11").fetchall()##计算机类工作top图cate2
    #     exp = db.session.execute("select * from(select exp,(sum(salary)/count(*)) as avg from job group by exp)job order by avg DESC ")##经验与月薪
    #     exp2 = db.session.execute("select * from(select exp,(sum(salary)/count(*)) as avg from job group by exp)job order by avg DESC ")  ##经验与月薪
    #     # print(num)
    #     edu = db.session.execute("select edu,count(*) from job group by edu").fetchall()##学历要求
    #     expzb = db.session.execute("select exp,count(*) from job group by exp").fetchall()##经验占比
    #     cszp = db.session.execute("select city,sum(num) from job group by city").fetchall()##城市招聘人数
    #
    #     cate2_2 = db.session.execute(
    #         "select * from(select cate2,city,avg(salary)as avg_sal from job group by cate2,city)job order by avg_sal DESC limit 500").fetchall()  ##计算机类工作top图cate2
    #     return render_template("tt.html",num=num,shuliang=shuliang,cate2=cate2,exp=exp,exp2=exp2,edu=edu,expzb=expzb,cszp=cszp,cate2_2=cate2_2)

    # 注册蓝图
    from job.views.test import test
    from job.views.main import main
    from job.views.jobitem import job
    from job.views.ind import ind
    from job.views.report import report
    app.register_blueprint(test,url_prefix="/test")
    app.register_blueprint(main,url_prefix="/main")
    app.register_blueprint(job,url_prefix="/job2")
    app.register_blueprint(ind, url_prefix="/ind2")
    app.register_blueprint(report, url_prefix="/report")

    # 注册
    from job.extensions import register_extension
    register_extension(app)

    # 注册数据库
    db.init_app(app)
    
    return app
